package com.ruoyi.common.utils.j2cpp;

import cn.hutool.core.io.resource.ClassPathResource;
import cn.hutool.core.util.RuntimeUtil;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;

import java.nio.charset.StandardCharsets;

/**
 * wcocr.pyd 需要放入到python执行的环境中，如： python.exe里面的.venv/Lib/site-packages中
 */
public class WechatOcr {

    public static JSONArray call(String imgPath, String pythonPath, String wechatRuntimePath, String wechatExePath) {
        ClassPathResource resource = new ClassPathResource("wx_ocr.py");
        String result = RuntimeUtil.execForStr( StandardCharsets.UTF_8, pythonPath, resource.getAbsolutePath(), wechatExePath, wechatRuntimePath, imgPath);
        JSONObject jsonObject = JSONUtil.parseObj(result);
        JSONArray res = jsonObject.getJSONArray("ocr_response");
        return res;
    }
}
